package ModelLayer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class Order {
	
	private int orderId;
	private String date;
	private Customer customer;
	private Employee employee;
	private Invoice invoice;
	private ArrayList<PartOrder> partOrders;
	
	
	public Order(Customer customer, Employee employee) 
	{
	    orderId = 1;
	    date = getDateTime();
		this.customer = customer;
		this.employee = employee;
		partOrders = new ArrayList<PartOrder>();
	}
	
	public Order()
	{
		partOrders = new ArrayList<PartOrder>();
	}
	
	public void addPartOrder(PartOrder partOrder)
	{
		partOrders.add(partOrder);
		System.out.println("succes");
	}

	/**
	 * @return the orderId
	 */
	public int getOrderId() {
		return orderId;
	}

	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}

	


	/**
	 * @return the customer
	 */
	public Customer getCustomer() {
		return customer;
	}

	/**
	 * @return the employee
	 */
	public Employee getEmployee() {
		return employee;
	}

	

	/**
	 * @param orderId the orderId to set
	 */
	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}

	

	

	


	/**
	 * @return the partOrders
	 */
	public ArrayList<PartOrder> getPartOrders() {
		return partOrders;
	}

	/**
	 * @param partOrders the partOrders to set
	 */
	public void setPartOrders(ArrayList<PartOrder> partOrders) {
		this.partOrders = partOrders;
	}

	/**
	 * @param customer the customer to set
	 */
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * @param employee the employee to set
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	
	
	private String getDateTime() 
    {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
	
	public double getDiscount()
	{
		double discount = 0;
		if(customer.getType().equals("Private") && getTotalPrice() > 2500)
		{
			discount = 45;
		}
		else if(customer.getType().equals("Business") && getTotalPrice() > 1500)
		{
			discount = 250;
		}
		
		return discount;
			
	}
	
	public double getTotalPrice()
	{
		double totalPrice2 = 0;
		for(PartOrder partOrder : partOrders)
		{
			double totalPrice = partOrder.getProduct().getSalesPrice() * partOrder.getAmount();
			totalPrice2 = totalPrice2 + totalPrice + 45;
		}
		return totalPrice2;
		
	}
	
	public double getTotalPriceWithDiscount()
	{
		double totalPriceWithDiscount = getTotalPrice() - getDiscount();
		return totalPriceWithDiscount;
	}

	/**
	 * @return the invoice
	 */
	public Invoice getInvoice() {
		return invoice;
	}

	/**
	 * @param invoice the invoice to set
	 */
	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}
	
	
	

	

}
